package com.gzm.check.utils;

import lombok.Getter;

import java.util.Arrays;

/**
 * 体检数据对应的枚举类(血清)
 * 首个参数放的是对应的代码值,
 * 使用数组是因为,不同设备上传上来的代码值有可能是不同的例如
 * A设置上传上来的白细胞数代码为A B设备上传的代码值为B ,虽然代码值不同但是对应的值应该是相同的,方便扩展
 * 下列参数均为对象字段名称,用反射获取字段,为之赋值和获取值
 * 第二个参数名为血常规中对应字段的字段名称
 * 第三个字段为对象结果单位
 * 第四个对象为参考值上限
 * 第五个对象为参考值下限
 */
@Getter
public enum SerumsEnum {

    //ALT	谷丙转氨酶
    ALT(new String[]{"ALT"}, "alt", "altUnit", "altUpper", "altLower"),
    //AST	谷草转氨酶
    AST(new String[]{"AST"}, "ast", "astUnit", "astUpper", "astLower"),
    //SGLU	葡萄糖
    SGLU(new String[]{"SGLU"}, "sglu", "sgluUnit", "sgluUpper", "sgluLower"),
    //TG	甘油三酯
    TG(new String[]{"TG"}, "tg", "tgUnit", "tgUpper", "tgLower"),
    //TC	总胆固醇
    TC(new String[]{"TC"}, "tc", "tcUnit", "tcUpper", "tcLower"),
    //CREA	肌酐
    CREA(new String[]{"CREA"}, "crea", "creaUnit", "creaUpper", "creaLower"),
    //UREA	尿素
    UREA(new String[]{"UREA"}, "ureaUnit", "urea", "ureaUpper", "ureaLower"),
    //HDL	高密度脂蛋白胆固醇
    HDL(new String[]{"HDL"}, "hdlc", "hdlcUnit", "hdlcUpper", "hdlcLower"),
    //LDL	低密度脂蛋白胆固醇
    LDL(new String[]{"LDL"}, "ldlc", "ldlcUnit", "ldlcUpper", "ldlcLower"),
    //TBIL	总胆红素
    TBIL(new String[]{"TBIL"}, "tbil", "tbilUnit", "tbilUpper", "tbilLower"),
    //DBIL	直接胆红素
    DBIL(new String[]{"DBIL"}, "dbil", "dbilUnit", "dbilUpper", "dbilLower"),
    //UA	尿酸
    UA(new String[]{"UA"}, "ua", "uaUnit", "uaUpper", "uaLower"),
    //IBIL	间接胆红素
    IBIL(new String[]{"IBIL"}, "ibil", "ibilUnit", "ibilUpper", "ibilLower");


    private String[] code;
    private String fieldName;
    private String fieldNameUnit;
    private String upper;
    private String lower;


    SerumsEnum(String[] code, String fieldName, String fieldNameUnit, String upper, String lower) {
        this.code = code;
        this.fieldName = fieldName;
        this.fieldNameUnit = fieldNameUnit;
        this.upper = upper;
        this.lower = lower;
    }

    public static String getFieldName(String code) {
        for (SerumsEnum c : SerumsEnum.values()) {
            if (Arrays.asList(c.getCode()).contains(code)) {
                return c.fieldName;
            }
        }
        return null;
    }

    public static String getFieldNameUnit(String code) {
        for (SerumsEnum c : SerumsEnum.values()) {
            if (Arrays.asList(c.getCode()).contains(code)) {
                return c.fieldNameUnit;
            }
        }
        return null;
    }

    public static String getLower(String code) {
        for (SerumsEnum c : SerumsEnum.values()) {
            if (Arrays.asList(c.getCode()).contains(code)) {
                return c.lower;
            }
        }
        return null;
    }

    public static String getUpper(String code) {
        for (SerumsEnum c : SerumsEnum.values()) {
            if (Arrays.asList(c.getCode()).contains(code)) {
                return c.upper;
            }
        }
        return null;
    }

}
